package com.viphuli.app.tool.adapter;

import java.util.List;

import android.graphics.Color;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.TextView;
import butterknife.Bind;
import butterknife.ButterKnife;

import com.offroader.utils.StringUtils;
import com.offroader.utils.ViewUtils;
import com.tencent.bugly.crashreport.CrashReport.UserStrategy;
import com.viphuli.app.tool.R;
import com.viphuli.app.tool.adapter.ArrangeTypeAdapter.ViewHolder;
import com.viphuli.app.tool.bean.part.ArrangeType;
import com.viphuli.app.tool.bean.part.ArrangeViewUserStatistics;
import com.viphuli.app.tool.common.MyApp;
import com.viphuli.app.tool.utils.ImageUtils;

public class ArrangeUserStatisticsAdapter extends BaseAdapter {
	private List<ArrangeViewUserStatistics> list;

	public ArrangeUserStatisticsAdapter(List<ArrangeViewUserStatistics> list) {
		this.list = list;
	}

	@Override
	public int getCount() {
		return list.size();
	}

	@Override
	public Object getItem(int index) {
		return list.get(index);
	}

	@Override
	public long getItemId(int index) {
		return index;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {

		ViewHolder holder = null;

		if (convertView == null || convertView.getTag() == null) {
			convertView = ViewUtils.inflateView(MyApp.getInstance(),
					R.layout.frag_arrange_statistics_list_item);
			holder = new ViewHolder(convertView);
			convertView.setTag(holder);

		} else {
			holder = (ViewHolder) convertView.getTag();
		}

		ArrangeViewUserStatistics arrangeTypeInfo = list.get(position);
		if (arrangeTypeInfo != null) {
			if (arrangeTypeInfo.getInfo() != null
					&& arrangeTypeInfo.getInfo().size() > 0) {
				BaseAdapter adapter = new ArrangeMonthViewGirdAdapter(
						arrangeTypeInfo.getInfo());
				holder.gv.setAdapter(adapter);
			}
			if (arrangeTypeInfo.getUser() != null
					&& !StringUtils.isEmpty(arrangeTypeInfo.getUser()
							.getUserName())) {
				holder.userName.setText(arrangeTypeInfo.getUser().getUserName()
						+ "的班次统计");
			}
		}
		return convertView;
	}

	protected class ViewHolder {

		@Bind(R.id.id_username_tv)
		TextView userName;

		@Bind(R.id.id_view_month_statistics_girdview)
		GridView gv;

		public ViewHolder(View view) {
			ButterKnife.bind(this, view);
		}
	}
}
